package www.bplead.com.controller.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by wangyangzi on 2016/10/19.
 */
public class DbOpenHelper extends SQLiteOpenHelper {
    private static final int VERSION = 1;
    private static final String DATABASE_NAME = "demo.db";

    public DbOpenHelper(Context context) {
        super(context, DATABASE_NAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE " + DbConstant.Tables.TABLE_STUDENT + "(" +
                DbConstant.TableStudent._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                DbConstant.TableStudent.NAME + " TEXT," +
                DbConstant.TableStudent.NO + " TEXT," +
                DbConstant.TableStudent.CLASS_ID + " INTEGER," +
                DbConstant.TableStudent.COURSE_ID + " INTEGER" +
                ")");
        db.execSQL("CREATE TABLE " + DbConstant.Tables.TABLE_CLASS + "(" +
                DbConstant.TableClass._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                DbConstant.TableClass.NAME + " TEXT " +
                ")");
        db.execSQL("CREATE TABLE " + DbConstant.Tables.TABLE_COURSE + "(" +
                DbConstant.TableClass._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                DbConstant.TableClass.NAME + " TEXT " +
                ")");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if(oldVersion >= newVersion) {
            return;
        }
    }
}
